import * as types from "../types";
import { getMenu } from "@/api";

export default {
  state: {
    menus: [],
  },
  getters: {
    menus: (state) => state.menus,
  },
  mutations: {
    [types.SET_MENU](state, menus) {
      state.menus = menus;
    },
  },
  actions: {
    async [types.SET_MENU]({ commit }) {
      try {
        const menus = await getMenu();
        commit(types.SET_MENU, menus);
      } catch (e) {
        return Promise.reject(e);
      }
    },
  },
};
